﻿use master
	if DB_ID('Lib') is not null
		drop database Lib
go

create database Lib
go

use Lib
create table Books
(
	bID int primary key identity(1,1),
	bCode nvarchar(100),
	bName nvarchar(100),
	bAuthor nvarchar(100),
	bStatus BIT DEFAULT(1)
)

create table History
(
	hID int primary key identity(1,1),
	bID int foreign key references Books,
	bDate smalldatetime default(getdate()),
	rDate smalldatetime,
	uName nvarchar(200)
)

INSERT INTO Books (
	bCode,
	bName,
	bAuthor,
	bStatus
) VALUES (
	/* bCode - nvarchar(100) */ N'B001',
	/* bName - nvarchar(100) */ N'Những cuộc phiêu lưu của Sherlock Holmes',
	/* bAuthor - nvarchar(100) */ N'Conal Doyle',
	/* bStatus - bit */ 0 ) 
	
INSERT INTO Books (
	bCode,
	bName,
	bAuthor,
	bStatus
) VALUES (
	/* bCode - nvarchar(100) */ N'B002',
	/* bName - nvarchar(100) */ N'Nhật ký gái gọi Manhattan',
	/* bAuthor - nvarchar(100) */ N'Kevil Philips',
	/* bStatus - bit */ 1 ) 
	
INSERT INTO Books (
	bCode,
	bName,
	bAuthor,
	bStatus
) VALUES (
	/* bCode - nvarchar(100) */ N'B003',
	/* bName - nvarchar(100) */ N'Thư tình gửi một người',
	/* bAuthor - nvarchar(100) */ N'Bình Minh',
	/* bStatus - bit */ 1 )
	
	
INSERT INTO History (
	bID,
	bDate,
	uName
) VALUES ( 
	/* bID - int */ 1,
	/* bDate - smalldatetime */ '2011-6-10 13:29:36.890',
	/* uName - nvarchar(200) */ N'Đỗ Minh Dương' )
	
INSERT INTO History (
	bID,
	bDate,
	rDate,
	uName
) VALUES ( 
	/* bID - int */ 2,
	/* bDate - smalldatetime */ '2011-6-10 13:29:36.890',
	/* rDate - smalldatetime */ '2011-6-14 13:29:36.890',
	/* uName - nvarchar(200) */ N'Đào Hùng Cường' )
	
INSERT INTO History (
	bID,
	bDate,
	rDate,
	uName
) VALUES ( 
	/* bID - int */ 1,
	/* bDate - smalldatetime */ '2011-5-10 13:29:36.890',
	/* rDate - smalldatetime */ '2011-5-14 13:29:36.890',
	/* uName - nvarchar(200) */ N'Phạm Quốc Sử' )
	
  SELECT * FROM Books
  SELECT * FROM History